<?php //====================================================================================== // // Function: Create dir // // Programmer: JKJ // Date : 2025-05-13 // // Copyright Reeft A/S (c) - 2025 //====================================================================================== // https://tinyfilemanager.github.io/ // https://tinyfilemanager.github.io/config-sample.txt //====================================================================================== // General config //====================================================================================== include "config/config.php"; //====================================================================================== // Set language //====================================================================================== include "include/set_language.php"; //====================================================================================== // Get input //====================================================================================== if (isset($_REQUEST["input_string"])) { $input_string = $_REQUEST["input_string"]; } else { $input_string = ''; } if (isset($_REQUEST["input_dir"])) { $input_dir = $_REQUEST["input_dir"]; } else { $input_dir = 'data_log'; } if (isset($_REQUEST["input_tinyfilemanager_dir"])) { $input_tinyfilemanager_dir = $_REQUEST["input_tinyfilemanager_dir"]; } else { $input_tinyfilemanager_dir = ''; } //====================================================================================== // Set defaults //====================================================================================== $entries_found = 0; $currentDate = date('Y-m-d'); $currentTime = date('H:i:s'); $returnCode = '00'; $returnMsg = 'Alles ist gut'; $returnCodeTiny = '00'; $returnMsgTiny = 'Alles ist gut'; $returnCodeLogDB = '00'; $returnMsgLogDB = 'Alles ist gut'; $input_exists = 'N'; //====================================================================================== // Set header //====================================================================================== header('Content-Type: application/json;charset=utf-8'); //====================================================================================== // Check content //====================================================================================== if ( $input_string == '' ) { $returnCode = '97'; $returnMsg = 'No input string passed to program'; $aryHeader = array(); $aryHeader["entries_found"] = $entries_found; $aryHeader["returnCode"] = $returnCode; $aryHeader["returnMsg"] = $returnMsg; $aryHeader["currentDate"] = $currentDate; $aryHeader["currentTime"] = $currentTime; $aryHeader["input_exists"] = $input_exists; $aryHeader["input_string"] = $input_string; // Create array and prepare for json encoding $returnJson["header"] = $aryHeader; // Paint it black echo(json_encode($returnJson)); exit; } //====================================================================================== // Start me up... //====================================================================================== $starttime = microtime(true); //====================================================================================== // Check if database file exists //====================================================================================== if (!file_exists($input_string)) { $input_exists = 'N'; if (!mkdir($input_string, 0777, true)) { $returnCode = '98'; $returnMsg = $input_string . ' was not created'; } else { $returnCode = '00'; $returnMsg = $input_string . ' created'; } } else { $input_exists = 'Y'; $entries_found = 1; $entries_found = 0; $returnCode = '99'; $returnMsg = $input_string . ' already exists'; } //====================================================================================== // Copy log db and tinyfilemanager //====================================================================================== if ( $DFT_DIR_WHERE_TO_SAVE_DB_LOG == $input_dir ) { $from = $DFT_DIR_PATH_LOG_TEMPLATE . '/' . $DFT_DB_LOG_TEMPLATE; $to = $input_string . '/' . $DFT_DB_LOG_TEMPLATE; if ( file_exists( $to )) { $returnCodeLogDB = '98'; $returnMsgLogDB = 'Integartion database already exists and is not copied - ' . ' from: ' . $from . ' - to: ' . $to; } else { if (!copy($from, $to)) { $returnCodeLogDB = '99'; $returnMsgLogDB = 'Could not copy integartion database - ' . ' from: ' . $from . ' - to: ' . $to; } else { $returnCodeLogDB = '00'; $returnMsgLogDB = 'Integartion database copied - ' . ' from: ' . $from . ' - to: ' . $to; } } //=============================================== // If log dir - also create tinyfilemanager stuff AR: we do not, since folder are located outside the apache server //=============================================== // Make the dir // $tinyfilemanager_path = $input_tinyfilemanager_dir . '/' . $DFT_TINYFILEMANAGER_BASE_NAME; // // if ( !file_exists($tinyfilemanager_path )) { // // if (!mkdir( $tinyfilemanager_path )) // { // $returnCodeTiny = '99'; // $returnMsgTiny = 'Could not create tinyfilemanager dir and programs'; // // } else { // // $returnCodeTiny = '00'; // $returnMsgTiny = 'Tinyfilemanager dir and programs created...'; // // foreach ( $DFT_TINYFILEMANAGER_COPY_PROGRAMS as $k => $v) { // // $from = $DFT_TINYFILEMANAGER_COPY_FROM_PATH . $v; // $to = $input_tinyfilemanager_dir . '/' . $DFT_TINYFILEMANAGER_BASE_NAME . $v; // // if (!copy($from, $to)) { // // Something could happen here.. // } // // } // // } // } else { // // $returnCodeTiny = '01'; // $returnMsgTiny = 'Tinyfilemanager dir already exists...'; // } } else { // Create dummy for git $from = $DFT_DIR_PATH_LOG_TEMPLATE_DUMMY . '/' . $DFT_DB_LOG_TEMPLATE_DUMMY; $to = $input_string . '/' . $DFT_DB_LOG_TEMPLATE_DUMMY; if (!copy($from, $to)) { $returnCodeLogDB = '99'; $returnMsgLogDB = 'Could not copy dummy file - ' . ' from: ' . $from . ' - to: ' . $to; } else { $returnCodeLogDB = '00'; $returnMsgLogDB = 'Dummy file copied - ' . ' from: ' . $from . ' - to: ' . $to; } $returnCodeLogDB = '01'; $returnMsgLogDB = 'Not a candidate to copy Integartion database'; } //====================================================================================== // Calculate response time //====================================================================================== $endtime = microtime(true); $response_time = $endtime - $starttime; $response_time = number_format($response_time, 6, '.', ''); $response_time_raw = number_format($response_time, 6, '.', ''); $response_time = '(' . $response_time . ' seconds)'; $response_time_raw = $response_time_raw; //====================================================================================== // Create header //====================================================================================== $aryHeader = array(); $aryHeader["entries_found"] = $entries_found; $aryHeader["returnCode"] = $returnCode; $aryHeader["returnMsg"] = $returnMsg; $aryHeader["returnCode"] = $returnCodeTiny; $aryHeader["returnMsgTiny"] = $returnMsgTiny; $aryHeader["returnCodeLogDB"] = $returnCodeLogDB; $aryHeader["returnMsgLogDB"] = $returnMsgLogDB; $aryHeader["currentDate"] = $currentDate; $aryHeader["currentTime"] = $currentTime; $aryHeader["input_exists"] = $input_exists; $aryHeader["input_string"] = $input_string; $aryHeader["input_dir"] = $input_dir; $aryHeader["DFT_DIR_WHERE_TO_SAVE_DB_LOG"] = $DFT_DIR_WHERE_TO_SAVE_DB_LOG; $aryHeader["response_sec"] = $response_time; $aryHeader["response_sec_raw"] = $response_time_raw; // Create array and prepare for json encoding $returnJson["header"] = $aryHeader; //====================================================================================== // Paint it black //====================================================================================== echo(json_encode($returnJson)); ?>